package net.es.weathermap.topo;

public class TopoUtils {

    /**
     * see: http://mathforum.org/library/drmath/view/51722.html
     *
     * @param latA 1st point latitude in degrees, signed
     * @param lonA 1st point longitude in degrees, signed
     * @param latB 2nd point latitude in degrees, signed
     * @param lonB 2nd point longitude in degrees, signed
     * @return distance in miles
     */
    public static Double distance(Double latA, Double lonA, Double latB, Double lonB) {
        Double earthRadiusMiles = 6652.84;
        latA = Math.toRadians(latA);
        lonA = Math.toRadians(lonA);
        latB = Math.toRadians(latB);
        lonB = Math.toRadians(lonB);
        Double aob = Math.cos(latA)*Math.cos(latB)*Math.cos(lonB-lonA) + Math.sin(latA)*Math.sin(latB);
        Double distance = earthRadiusMiles * Math.acos(aob);
        return distance;
    }
}
